//index.js
const app = getApp()
const DB = wx.cloud.database();
let len = "";
let len2 = "";
Page({
  data: {
    type: '',
    // top标签显示（默认不显示）
    backTopValue: false,
    orderItem: [],
    orderItem2: [],
    banner: [{
        img: 'cloud://cloud1-7ge3r2d44d1ee4ba.636c-cloud1-7ge3r2d44d1ee4ba-1310918076/yiqing.jpg'
      },
      {
        img: 'cloud://cloud1-7ge3r2d44d1ee4ba.636c-cloud1-7ge3r2d44d1ee4ba-1310918076/my.png'
      },
      {
        img: 'cloud://cloud1-7ge3r2d44d1ee4ba.636c-cloud1-7ge3r2d44d1ee4ba-1310918076/admin.png'
      },
    ],
    fenleitype: ['全部', 'hpv疫苗',"新冠疫苗", "轮状疫苗", "狂犬疫苗", '流感疫苗', "乙肝疫苗", "肺炎疫苗"]
  },
  onLoad: function () {

    this.setData({
      type: wx.getStorageSync('user').xinwentype
    })

  },

  onShow() {

    len2 = this.data.orderItem2.length
    DB.collection('yimiao').where({

    }).skip(len).orderBy('time_order', 'desc').get().then(res => {
      let oldData = this.data.orderItem2;
      console.log("b", res)
      wx.hideLoading();
      this.setData({
        orderItem2: res.data
      })
      console.log("this", this.data.orderItem2)
    })

  },


  onChange(e) {

    if (e.detail.title === '全部') {
      DB.collection('yimiao').where({})
        .get()
        .then((res) => {
          console.log(res)
          this.setData({
            orderItem2: res.data,
          })
        })

    } else {
      DB.collection('yimiao').where({
          yimiaotype: e.detail.title
        })
        .get()
        .then((res) => {
          console.log(res)
          this.setData({
            orderItem2: res.data,
          })
        })
    }

  },


  goDetail(e) {
    wx.navigateTo({
      url: '../yimiaodetail/index?id=' + e.currentTarget.dataset.id,
    })
  },

  sousuo() {
    console.log('e')
    wx.navigateTo({
      url: '../sou/index',
    })
  },

  // 监听滚动条坐标
  onPageScroll: function (e) {
    var scrollTop = e.scrollTop
    var backTopValue = scrollTop > 500 ? true : false
    this.setData({
      backTopValue: backTopValue
    })
  },

  // 滚动到顶部
  backTop: function () {
    // 控制滚动
    wx.pageScrollTo({
      scrollTop: 0
    })
  },
})